package com.dealin.writer.bean;


import com.google.gson.Gson;

import org.json.JSONObject;

import java.util.Date;

/**
 * Created by lenovo on 2016/6/20.
 */
public class Chapter {
    private String name="未命名",content="",createDate=new Date().toLocaleString(),refreshDate=new Date().toLocaleString(),summary="暂无摘要",password="无";
    private int count=0,id=-1;
    public Chapter()
    {

    }
    public Chapter(JSONObject jo) throws Exception
    {
        init(jo);
    }
    //初始化
    public void init(JSONObject project) throws Exception
    {
        name=project.getString("name");
        content=project.getString("content");
        createDate=project.getString("createDate");
        refreshDate=project.getString("refreshDate");
        password=project.getString("password");
        summary=project.getString("summary");
        count=project.getInt("count");
        id = project.getInt("id");
    }
    //转换为JSONObject
    public String toJSONObject() throws Exception
    {
        /*JSONObject project=new JSONObject();
        project.put("name",name);
        project.put("content",content);
        project.put("createDate",createDate);
        project.put("refreshDate",refreshDate);
        project.put("password",password);
        project.put("summary",summary);
        project.put("count",count);*/
        return new Gson().toJson(this);
    }
    /*
    **以下是get方法
     */
    public String  getContent()
    {
        return content;
    }
    public String getName()
    {
        return name;
    }
    public int getCount(){
        return count;
    }
    /*public String getAuthor()
    {
        return author;
    }*/
    public String getCreateDate()
    {
        return createDate;
    }
    public String getRefreshDate()
    {
        return refreshDate;
    }
    public String getSummary()
    {
        return summary;
    }
    public String getPassword()
    {
        return password;
    }
    public int getId() {
        return id;
    }
    /*
    **以下是set方法
     */
    public void setName(String s)
    {
        name=s;
    }
    public void setContent(String s)
    {
        content=s;
        count=s.replaceAll("\n|\t|\\s","").length();
        refreshDate=new Date().toLocaleString();
    }
    public void setCreateDate(String s)
    {
        createDate=s;
    }
    public void setRefreshDate(String s)
    {
        refreshDate=s;
    }
    public void setSummary(String s)
    {
        summary=s;
    }
    public void setPassword(String s)
    {
        password=s;
    }
    public void setId(int id){this.id=id;
    }
}

